{% extends "profiles/base.html" %}

{% load i18n %}
{% load avatar_tags %}
{% load uni_form %}

{% block head_title %}{% blocktrans %}Profile for {{ other_user }}{% endblocktrans %}{% endblock %}

{% block body %}
    
    <div class="right_panel">
        {% include "profiles/profile_side_panel.html" %}
    </div>
    
    <div class="left_panel">
        <div id="profile_avatar">
            <div>{% avatar other_user 80 %}</div>
            {% if is_me %}
            <a href="{% url avatar_change %}" id="avatar_replace">(replace)</a>
            {% endif %}
        </div>
        
        <h1>{% blocktrans %}Profile for {{ other_user }}{% endblocktrans %}</h1>
        
        <div class="profile_info">
            {% if other_user.get_profile.name %}<p><b>{% trans "Name" %}</b>: {{ other_user.get_profile.name }}</p>{% endif %}
            {% if other_user.get_profile.about %}<p><b>{% trans "About" %}</b>: {{ other_user.get_profile.about }}</p>{% endif %}
            {% if other_user.get_profile.location%}<p><b>{% trans "Location" %}</b>: {{ other_user.get_profile.location }}</p>{% endif %}
            {% if other_user.get_profile.website %}<p><b>{% trans "Website" %}</b>: <a href="{{ other_user.get_profile.website }}">{{ other_user.get_profile.website }}</a></p>{% endif %}
        </div>
        
        {% if user.is_authenticated %}
            <p>
                {% url tweet_following other_user as the_following_url %}
                {% if the_following_url %}
                    <a href="{{ the_follower_url }}">{% trans "Followers" %}</a>: {{ other_user.followers.count|default:"0" }}
                {% endif %}
                {% url tweet_followers other_user as the_follower_url %}
                {% if the_follower_url %}
                    <a href="{{ the_following_url }}">{% trans "Following" %}</a>: {{ other_user.followed.count|default:"0" }}
                {% endif %}            </p>
            
            {% if is_me %}
                <div class="form-toggle">
                <p><span id="edit-profile-toggle">{% trans "Edit profile" %}</span></p>
                
                <form class="uniForm" id="edit-profile" method="POST" action="" style="display: none;">
                    <fieldset class="inlineLabels">  
                        {{ profile_form|as_uni_form }}
                        <div class="form_block">
                        <input type="hidden" name="action" value="update" />
                        <input type="submit" value="{% trans "update" %}"/>
                        </div>
                    </fieldset>
                </form>
                </div>
            {% else %}
                {# @@@ this could be done with ajax, or at the very least turned into an inclusion tag #}
                <div>
                    {% url toggle_follow other_user as the_toggle_url %}
                    {% if the_toggle_url %}
                    <form method="POST" action="{% url toggle_follow other_user %}">
                        {% if is_following %}
                            <input type="hidden" name="action" value="unfollow" /><input type="submit" value="{% trans "unfollow" %}"/>
                        {% else %}
                            <input type="hidden" name="action" value="follow" /><input type="submit" value="{% trans "follow tweets" %}"/>
                        {% endif %}
                    </form>
                    {% endif %}
                </div>
                
                {# @@@ this should be an inclusion tag #}
                {% if is_friend %}
                    <p>{% blocktrans %}You are friends with {{ other_user }}.{% endblocktrans %} <a href="{% url messages_compose %}{{ other_user }}/">{% trans "Send a message" %}</a>.</p>
                {% else %}
                    {% if previous_invitations_from %}
                        <p>{% blocktrans %}{{ other_user }} has requested friendship.{% endblocktrans %}</p>
                        {% for invitation in previous_invitations_from %}
                            <div class="friendship_request">
                                <p>From <a href="{% url profile_detail invitation.from_user.username %}">{{ invitation.from_user }}</a> ({{ invitation.sent }}):</p>
                                <p class="invitation_message">{{ invitation.message }}</p>
                                <form method="post" action="">
                                    <input type="hidden" name="invitation" value="{{ invitation.id }}"/>
                                    <input type="hidden" name="action" value="accept"/>
                                    <input type="submit" value="{% trans 'accept' %}" />
                                </form>
                            </div>
                        {% endfor %}
                    {% else %}
                        {% if previous_invitations_to %}
                            <p>{% trans "Friendship request sent." %}</p>
                        {% else %}
                            {% if invite_form %}
                                <h2>{% trans "Add As Friend" %}</h2>
                                <form class="uniForm" method="POST" action="">
                                    <fieldset class="inlineLabels">  
                                        {{ invite_form|as_uni_form }}
                                        <div class="form_block">
                                            <input type="hidden" name="action" value="invite" />
                                            <input type="submit" value="{% trans "invite" %}"/>
                                            {% blocktrans %}{{ other_user }} to be a friend.{%  endblocktrans %}
                                        </div>
                                    </fieldset>
                                </form>
                            {% endif  %} {# invite_form #}
                        {% endif %} {# previous_invitations_to #}
                    {% endif %} {# previous_invitations_from #}
                {% endif %} {# is_friend #}
                
            {% endif %} {# is me #}
            
        {% else %} {# not user.is_authenticated #}
            {% url acct_signup as signup_url %}
            {% url acct_login as login_url %}
            <p>{% blocktrans %}<a href="{{ signup_url }}">Sign up</a> and <a href="{{ login_url }}">log in </a> to add this person as a friend and see their tweets and blog posts.{% endblocktrans %}</p>
        {% endif %}
    </div>
{% endblock %}

{% block extra_body %}
    <script type="text/javascript">
        $(document).ready(function() {
            $('#edit-profile').hide();
            $('#edit-profile-toggle').click(function() {
                $('#edit-profile').toggle();
                $('#edit-profile').autoscroll();
                return false;
            });
            if ($('#edit-profile ul.errorlist').length) {
                $('#edit-profile').show();
                $('#edit-profile ul.errorlist').autoscroll();
            }
        });
    </script>
{% endblock %}

